package us.nchu.tomtiger.service;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import us.nchu.tomtiger.dao.ProjectDao;
import us.nchu.tomtiger.dao.ProjectPendingDao;
import us.nchu.tomtiger.dao.UserDao;
import us.nchu.tomtiger.dao.UserPendingDao;
import us.nchu.tomtiger.model.Project;
import us.nchu.tomtiger.model.ProjectPending;
import us.nchu.tomtiger.model.UserPending;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by XiongXuan on 2018/1/11.
 */
@Service
public class ProjectPendingService {
    @Resource
    private ProjectPendingDao projectPendingDao;
    @Resource
    private ProjectDao projectDao;

    public List<ProjectPending> getUncheckedList() {
        return projectPendingDao.queryForUnchecked();
    }

    public void createProjectPending(ProjectPending projectPending) {
        projectPendingDao.insert(projectPending);
    }

    @Transactional
    public void publishProject(ProjectPending projectPending, String adminId) {
        projectPendingDao.checkAndUpdateProject(projectPending, adminId);
        if (projectPending.getResult() == 1)
            projectDao.checkProject(projectPending.getPendingProjectId());
    }
}
